<?php
namespace Todo\Model\Msg;

use Todo\Model\BaseModel;

class ReadModel extends BaseModel
{
    public $tableName = 'msg_read';

    public $_validate = array(
        array('user_id', 'require', '必须有用户'),
        array('content_id', 'require', '消息不能为空')
    );

    protected $_auto = array(
        array('read_time', '_timestamp', self::MODEL_BOTH, 'callback'),
        array('title', '_title', self::MODEL_BOTH, 'callback'),
        array('tnt_id', 'auto_tnt', self::MODEL_INSERT, 'function')
    );

    protected function _timestamp(){
        return date('Y-m-d H:i:s');
    }

    protected function _title(){
        if(!$this->content_id) return;

        $Model = new ContentModel();
        $info = $Model->$this->keyFind($this->content_id);
        if(!$info) return false;

        $this->title = $info['title'];
        $this->sender = $info['sender'];
        if($info['sender']){
            $this->sender_name == D('Todo/Sys/User')->keyFind($info['sender'], 'nickname');
        }else{
            $this->sender_name == '系统';
        }
        $this->sender_time = $info['sender_time'];
        return $info['title'];
    }
}